using System;
using System.IO;
using System.IO.IsolatedStorage;
namespace Salient.SharpZipLib
{
	public static class IsolatedStreamUtilities
	{
		public static void CopyFile(this IsolatedStorageFile store, string source, string target)
		{
			using (IsolatedStorageFileStream isolatedStorageFileStream = store.OpenFile(source, 3))
			{
				using (IsolatedStorageFileStream isolatedStorageFileStream2 = store.CreateFile(target))
				{
					isolatedStorageFileStream.CopyTo(isolatedStorageFileStream2);
				}
			}
		}
		public static long GetFilesize(string filename)
		{
			long fileSize;
			using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
			{
				fileSize = userStoreForApplication.GetFileSize(filename);
			}
			return fileSize;
		}
		public static long GetFileSize(this IsolatedStorageFile store, string filename)
		{
			long length;
			using (IsolatedStorageFileStream isolatedStorageFileStream = store.OpenFile(filename, 3, 1, 1))
			{
				length = isolatedStorageFileStream.get_Length();
			}
			return length;
		}
		public static void CopyTo(this MemoryStream memoryStream_0, Stream dest)
		{
			dest.Write(memoryStream_0.GetBuffer(), (int)memoryStream_0.get_Position(), (int)(memoryStream_0.get_Length() - memoryStream_0.get_Position()));
		}
		public static void CopyTo(this Stream stream_0, MemoryStream dest)
		{
			if (stream_0.get_CanSeek())
			{
				int i = (int)dest.get_Position();
				int num = (int)(stream_0.get_Length() - stream_0.get_Position()) + i;
				dest.SetLength((long)num);
				while (i < num)
				{
					i += stream_0.Read(dest.GetBuffer(), i, num - i);
				}
			}
			else
			{
				stream_0.CopyTo(dest);
			}
		}
		public static void CopyTo(this Stream stream_0, Stream dest)
		{
			int num = stream_0.get_CanSeek() ? Math.Min((int)(stream_0.get_Length() - stream_0.get_Position()), 8192) : 8192;
			byte[] array = new byte[num];
			int num2;
			do
			{
				num2 = stream_0.Read(array, 0, array.Length);
				dest.Write(array, 0, num2);
			}
			while (num2 != 0);
		}
		public static void MoveFile(this IsolatedStorageFile store, string source, string target)
		{
			store.CopyFile(source, target);
			store.DeleteFile(source);
		}
	}
}
